package mvc.model.dao.impl;

import mvc.common.BaseDao;
import mvc.model.dao.OrderDao;
import mvc.model.pojos.OrderBean;
import mvc.model.vo.Order;

import java.util.List;

public class OrderDaoImpl implements OrderDao {
    private static final BaseDao baseDao;
    static {
        baseDao = new BaseDao();
    }
    @Override
    public List<OrderBean> query(int uid) {
        String sql = "SELECT * FROM `order` WHERE `uid` = ?;";
        return baseDao.query(sql, OrderBean.class, uid);
    }

    @Override
    public OrderBean queryOne(int oid) {
        String sql = "SELECT * FROM `order` WHERE `oid` = ?;";
        List<OrderBean> query = baseDao.query(sql, OrderBean.class, oid);
        return query.isEmpty() ? null : query.get(0);
    }

    @Override
    public List<Order> queryVO(int uid) {
        String sql = "select o.oid,p.pname,pi.online,c.color,r.rsize,r.msize,o.price,o.count,o.sum,o.status,o.otime ,o.anumber from `order` o,`product` p,`p_info` pi,`rom` r,`color` c,cpu  where o.pid=p.pid and pi.number=p.number and pi.rid=r.rid and pi.cid = c.cid and pi.cpuid=cpu.cpuid and o.uid = ? order by o.otime desc;";
        return baseDao.query(sql, Order.class, uid);
    }

    @Override
    public Order queryOneVO(int oid) {
        String sql = "select o.oid,p.pname,pi.online,c.color,r.rsize,r.msize,o.price,o.count,o.sum,o.status,o.otime ,o.anumber from `order` o,`product` p,`p_info` pi,`rom` r,`color` c,cpu  where o.pid=p.pid and pi.number=p.number and pi.rid=r.rid and pi.cid = c.cid and pi.cpuid=cpu.cpuid and o.oid = ? order by o.otime desc;";
        List<Order> query = baseDao.query(sql, Order.class, oid);
        return query.isEmpty() ? null : query.get(0);
    }

    @Override
    public List<OrderBean> queryStatus(int uid, String status) {
        String sql = "select * from `order` where uid=? and status=?;";
        return baseDao.query(sql, OrderBean.class, uid, status);
    }
}
